﻿using System;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using psieve.factor;
using psieve.sieve;

namespace psieve
{
    class Program
    {
        private const int SWP_NOSIZE = 0x0001;

        [DllImport("kernel32.dll", ExactSpelling = true)]
        private static extern IntPtr GetConsoleWindow();

        [DllImport("user32.dll", ExactSpelling = true)]
        private static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy,
            int wFlags);


        static void Main(string[] args)
        {

            try
            {
                SetWindowPos(GetConsoleWindow(), 0, 2500, 300, 0, 0, SWP_NOSIZE);

                //9109301380158024037

                var primes = new Eratosthenes().Sieve(100).ToList();
                Console.WriteLine(String.Join(",", primes));


                //BigInteger n = 3265289;
                //1855804001
                //1769780809

                //BigInteger n = 823*937;

                //BigInteger n = BigInteger.Parse("501302029019823570236881");
                BigInteger n = BigInteger.Parse("700306329819482104517");

                //Console.WriteLine(n.IsProbablyPrime(2));

                //BigInteger a = BigInteger.Parse("26463220929");
                //Console.WriteLine(n % a);

                //var c = new TrialDivision(new Eratosthenes()).Factor(n).ToList();
                //c.ForEach(x => Console.WriteLine(x));

                //Console.WriteLine("-----------------");

                var f = new Fermat().Factor(n).ToList();
                f.ForEach(x => Console.WriteLine(x));

                Console.WriteLine("-----------------");
                Console.WriteLine(f.Product());

                //var t = Sieve.findPrimes(100000000);

                //Console.WriteLine(t);
                //Console.WriteLine(t.GetType());


                //var e = new Eratosthenes().Sieve(100000000);
                //var s = new Eratosthenes2().Sieve(100000000);

                //long c1 = e.LongCount();
                //long c2 = s.LongCount();

                //e.Zip(s, (e1, e2) => e1 + " : " + e2).ToList().ForEach(Console.WriteLine);

                //Console.WriteLine(e.SequenceEqual(s));

                //Console.WriteLine(c1 == c2);

                //e.ForEach(Console.WriteLine);
                //s.ForEach(Console.WriteLine);

                //throw new ApplicationException("aaa");




                //var res1 = sieve1.Sieve(500).ToList();
                //var res2 = sieve2.Sieve(500).ToList();

                ////res1.ToList().ForEach(Console.WriteLine);
                ////Console.WriteLine("---------------------------");
                ////res2.ToList().ForEach(Console.WriteLine);

                ////Console.WriteLine("---------------------------");

                //res1.Zip(res2, (e1, e2) => e1 + " : " + e2).ToList().ForEach(Console.WriteLine);

            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}
